<template>
<div>
  <h1>p5_Vue页面</h1>
  <h2>新闻添加</h2>
  <p>标题:<input type="text" v-model="form.title"></p>
  <p>内容:<input type="text" v-model="form.content"></p>
  <button @click="get_add">添加</button>

  <h1>展示新闻</h1>
  <table border="1">
    <tr>
      <td>标题</td>
      <td>内容</td>
    </tr>
    <tr v-for="i in show">
      <td>{{i.title}}</td>
      <td>{{i.content}}</td>
    </tr>
  </table>
  <button v-for="i in num" @click="get_get(i)">{{i}}</button>
</div>
</template>

<script>
export default {
  name: "p5_day01",
  data(){
    return{
      form:{},
      show:{},
      num:""
    }
  },
  methods:{
    get_add(){
      this.$axios.post('journalism/',this.form)
      .then(res=>{
        if (res.data.code==200){
          console.log(res.data)
          alert('添加成功')
          this.form={}
        }
        else {
          alert('添加失败')
        }
      })
    },
    get_get(i){
      this.$axios.get('journalism/?page='+i)
      .then(res=>{
        console.log(res.data)
        this.show = res.data.list
        this.num = res.data.num
      })
    },
  },
  mounted() {
    this.get_get(1)
  }

}
</script>

<style scoped>

</style>
